<template>
  <div class="app-container">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <el-select
            v-model="filter.lpo_id"
            size="small"
            :remote-method="selProoss"
            remote
            filterable
            style="width: 100%"
            placeholder="请选择合同"
            clearable
            @focus="selProoss"
          >
            <el-option
              v-for="item in sles"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            />
          </el-select>
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button size="small" @click="app.reset('filter')">清 空</el-button>
          <el-button type="primary" size="small" @click="getList">查 询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table ref="multipleTable" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="项目名称" width="220px" prop="pro_name" />
      <el-table-column label="PO单号" width="190px">
        <template slot-scope="{row}">
          {{ 'PO'+row.pro_id }}
        </template>
      </el-table-column>
      <el-table-column label="申请日期" width="140px" align="center" prop="create_time" />
      <el-table-column label="期别" width="120px" prop="stage" />
      <el-table-column label="用途" width="120px" prop="purpose" />
      <el-table-column label="本期付款" width="110px" align="right">
        <template slot-scope="{row}">
          {{ app.toFix(row.payment, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="本期扣款" width="110px" align="right">
        <template slot-scope="{row}">
          {{ app.toFix(row.deduction, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="本期实付" width="110px" align="right">
        <template slot-scope="{row}">
          {{ app.toFix(row.payment - row.deduction, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="小包进度" width="120px" prop="speed" />
      <el-table-column label="付款项目" width="120px" prop="type" />
      <el-table-column label="付款依据" width="120px" prop="basis" />
      <el-table-column label="付款条件" width="120px" prop="condition" />
      <el-table-column label="付款周期" width="120px" prop="cycle" />
      <el-table-column label="备注" min-width="260px" prop="remark" />
      <el-table-column label="操作" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="archives(row)">附 件</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Archives ref="archives" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import { selProoss, prooses } from '@/api/project'
import Pagination from '@/components/Pagination'
import Archives from './components/voucher/archives-dialog'

export default {
  name: '',
  components: { Pagination, Archives },
  inject: ['app'],
  data() {
    return {
      list: [],
      sles: [],
      dialog: {
        edit: {},
        title: '',
        type: ''
      },
      filter: {
        pageNumber: 10,
        pageCurrent: 1,
        pageAll: 1
      }
    }
  },
  created() {
    if (this.$route.query.lpo_id) {
      this.filter.lpo_id = this.$route.query.lpo_id
      const o = {}
      o.key = this.$route.query.lpo_id
      o.value = this.$route.query.lpo_name
      this.sles.push(o)
    }
    this.getList()
  },
  methods: {
    getList(e) {
      this.app.loading = true
      prooses({
        ...this.filter,
        ...e
      }).then(response => {
        this.list = response.list
        this.filter = response.filter
        this.app.removeLoding()
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    selProoss(query) {
      let str = ''
      if (Object.prototype.toString.call(query) === '[object String]') str = query
      selProoss({ name: str }).then(response => {
        this.sles = response.data
      }).catch(err => {
        this.$message.error(err)
      })
    },
    archives(e) {
      this.dialog.title = '工程外包支出附件'
      this.app.dialogParam(this.dialog.edit, ['lpoe_id', 'type'], { 'lpoe_id': e.id, 'type': '订单管理' })
      this.$refs['archives'].visible = true
    }
  }
}
</script>
